import random


class Insult_Manager:
    """Simple class that manages the insults.
    """

    def __init__(self, filename="list_insults.txt"):
        self.parse_file(filename)

    def parse_file(self, filename):
        """Opens an file with insults and creates a list with them.

        Doesn't return anything.
        """
        try:
            self.insults = open(filename, "r")
            self.insults = self.insults.readlines()

        except IOError:
            print "Insult_Manager didn't find the insult file."

    def get_insult(self):
        """Chooses a random insult read from the file.
        The $ from the string should be replace with the username.

        Returns a string.
        """
        index = random.randint(0, len(self.insults)-1)
        insult = self.insults[index]
        insult = insult.replace("\r\n", "").replace("\n", "")

        return insult
